package com.lagou.rpc.consumer.zookeeper;

import org.I0Itec.zkclient.ZkClient;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: liufh
 * @create: 2021-12-27 21:10
 **/
@Service
public class ZookeeperConServer {

    /**
     * 获取节点
     */
    public List<String> getNote() {
        ZkClient zkClient = new ZkClient("192.168.44.128:2181");

        String path = "/homework/service";
        // 获取子节点列表
        List<String> nodeList = zkClient.getChildren(path);
        System.out.println(nodeList);
        List<String> ipList = new ArrayList<>();
        for (String chilePath : nodeList) {
            // 读取节点内容
            String ip = zkClient.readData(path + "/" + chilePath);
            System.out.println(ip);
            ipList.add(ip);
        }
        return ipList;
    }

}
